// pages/salesmans/achievementDes/achievementDes.js
var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    record_data: [],
    page: 1,
    page_count: 1,
    noMore: false,
    loading: false,
    salesman_id:'',
    census:0,
    row:10
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.setData({
      salesman_id:options.id
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    that.rechargeOrder();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  reachBottom: function () {
    var that = this;
    var page = that.data.page + 1;
    if (page > that.data.page_count) {
      that.setData({
        noMore: true
      })
      return false;
    }
    that.setData({
      page: page
    })
    that.rechargeOrder();
  },
  rechargeOrder() {
    var that = this;
    app.ajax({
      url: 'Partner/Salesman/rechargeOrder',
      method: "POST",
      data: {
        id: that.data.salesman_id,
        page: that.data.page,
        row: that.data.row
      },
      success: function (res) {
        var flag = res.data;
        if (flag.code < 0){
            return false;
        }
        if (flag.data.data.length != 0 && that.data.record_data.length != 0) {
          if (that.data.record_data[that.data.record_data.length - 1].date == flag.data.data[0].date) {
            var tmp = that.data.record_data;
            var same_time = tmp[tmp.length - 1].child.concat(flag.data.data[0].child);
            tmp[tmp.length - 1].child = same_time;
            that.setData({
              record_data: tmp
            });
            flag.data.data.splice(0, 1);
          }
        }
        var record = that.data.record_data.concat(flag.data.data)
        var len = flag.data.data.length
        if (that.data.row > len) {
          that.setData({
            noMore: true
          })
        } else {
          that.setData({
            noMore: false
          })
        }
        that.setData({
          record_data: record,
          page_count: flag.data.page.page_count,
          census: flag.data.census,
        });
      }
    })
  },
  
})